﻿Option Strict On

Imports System.Collections.Specialized
Imports System.Windows.Forms
Imports System.IO
Imports System.Xml
Imports System.Linq
Imports System.Xml.Linq
Imports <xmlns:mg="Matching Game">
'Imports <xmlns="Matching Games">

Public Module Main
    Public MyGameset As New Gameset

    Public AppDir As String = AppDomain.CurrentDomain.BaseDirectory
    Public GameSoundPlayer As New System.Media.SoundPlayer("c:\windows\media\tada.wav")
    Public LowerChar As Integer = 33
    Public UpperChar As Integer = 126

    'number of icons squares, future (16/20/24/30/36)
    Public IconSquareCount As Integer

    Public GameCard As String
    Public GameCards As String
    Public GameCardList As New Specialized.StringCollection
    Public GameCardType As String
    Public GameCardFont As System.Drawing.Font
    Public GameSetFile As String
    Public DefaultGameSetFile As String = "DefaultGameSet.xml"
    Public GameMessage As String

    Public XDocGameSet As XDocument
    Public XDocGameCard As XElement

    Public GameBackColor As Color = Nothing
    Public GameForeColor As Color = Nothing
    Public IconBackColor As Color = Nothing
    Public IconForeColor As Color = Nothing


    Public Sub AddProperty(ByVal propertyName As String, _
      ByVal defaultValue As String, ByVal propertyType As Type)
        Dim providerName As String = "LocalFileSettingsProvider"

        Dim attributes As New Configuration.SettingsAttributeDictionary()
        Dim attr As New Configuration.UserScopedSettingAttribute()
        attributes.Add(attr.TypeId(), attr)

        Dim prop As New Configuration.SettingsProperty( _
         New Configuration.SettingsProperty(propertyName, propertyType, _
        My.MySettings.Default.Providers(providerName), False, defaultValue, _
        Configuration.SettingsSerializeAs.String, attributes, False, False))

        My.MySettings.Default.Properties.Add(prop)
    End Sub

    Public Function RandomIndex(ByVal IndexCount As Integer) As List(Of Integer)
        Dim rand = New Random
        Dim num As Integer
        Dim ListofIntegers As New List(Of Integer)
        Dim ListofIndices As New List(Of Integer)

        For intX As Integer = 1 To IndexCount
            ListofIntegers.Add(intX)
        Next

        For intX As Integer = 1 To IndexCount
            num = rand.Next(1, ListofIntegers.Count + 1)
            num = ListofIntegers(num - 1)
            ListofIndices.Add(num)
            ListofIntegers.Remove(num)
        Next

        Return ListofIndices
    End Function

    Public Function ShuffleStringArray(ByVal items() As String) As String()

        Dim ptr As Integer
        Dim alt As Integer
        Dim tmp As String
        Dim rnd As New Random()

        ptr = items.Length

        Do While ptr > 1
            ptr -= 1
            alt = rnd.Next(ptr - 1)
            tmp = items(alt)
            items(alt) = items(ptr)
            items(ptr) = tmp
        Loop

        Return items

    End Function


End Module

